#!/usr/bin/python
#coding=utf-8

import parser
import floatcalc_ply as calc
import unittest

class test(unittest.TestCase):
	OkValues = ( ("1+1", {}, "2.0"),
					("x", {'x':3}, "3.0"),
					("1+2*3", {'x':3}, "7.0"),
					("- x", {'x':3}, "-3.0"),
					("(x-2)*(x-2)", {'x':3}, "1.0"),
					("", {'x':3}, ""),
					("-x", {'x':3}, "-3.0")
				  )
	ErrorValues = ( ("1+1)", {}),
					#("(()())", {'x':3.0}, ""),
					("y", {'x':3}),
					("x+y", {'x':3}),
					("y+x", {'x':3}),
					("x:x", {'x':3}),
					("- x & 3", {'x':3})
				  )

	def testCalcOk(self):
		for s, d, res in self.OkValues:
			result = calc.formula(s, d)
			self.assertEqual(res, result)

	def testCalcError(self):
		for s, d in self.ErrorValues:
			self.assertRaises(calc.CalcError, calc.formula, s, d)

if __name__ == '__main__':
	unittest.main()